package com.tiger.cloud.service.rejection;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tiger.cloud.common.mybatis.MybatisTigerDao;
import com.tiger.cloud.common.mybatis.TigerBaseService;
import com.tiger.cloud.dao.crm.UserCompanyInfoDao;
import com.tiger.cloud.dao.rejection.RejectionDao;
import com.tiger.cloud.dao.rejection.UserRejectionDao;
import com.tiger.cloud.form.UserCompanyInfoForm;
import com.tiger.cloud.model.rejection.Rejection;
import com.tiger.cloud.model.rejection.UserRejection;
import com.tiger.cloud.util.Page;

/**
 * 接单/甩单
 */
@Service("rejectionService")
public class RejectionService extends TigerBaseService<Rejection> implements IRejectionService{
    
    @Autowired
	private RejectionDao rejectionDao;
    @Autowired
   	private UserRejectionDao userRejectionDao;
    @Autowired
    private UserCompanyInfoDao userCompanyInfoDao;
    
	@Override
	public MybatisTigerDao<Rejection> getEntityDao() {
		return rejectionDao;
	}

	public Map<String, Object> getByUserId(Long userId){
		return userCompanyInfoDao.getByUserId(userId);
	}
	
	@Override
	public Page<Rejection> pullRejection(Rejection re) {
		//省份id,城市id,用户userid
		int limitStart=re.getLimitStart(),limitEnd = re.getLimitEnd();
		long count = rejectionDao.pullRejectionCountByEntity(re);
		Page<Rejection> page = new Page<Rejection>((int)(limitEnd/(limitEnd-limitStart)), (limitEnd-limitStart));
		page.setData(rejectionDao.pullRejectionByEntity(re));
		page.setTotalCount(count);
		return page;
	}
	@Override
	public Page<Rejection> tradeFindFindByEntity(Rejection re) {
		int limitStart=re.getLimitStart(),limitEnd = re.getLimitEnd();
		long count = rejectionDao.countByEntity(re);
		Page<Rejection> page = new Page<Rejection>((int)(limitEnd/(limitEnd-limitStart)), (limitEnd-limitStart));
		page.setData(rejectionDao.tradeFindFindByEntity(re));
		page.setTotalCount(count);
		return page;
	}

	@Override
	public Long myRejectionCountByEntity(Rejection rejection) {
		return rejectionDao.myRejectionCountByEntity(rejection);
	}

	@Override
	public void removeRejection(Rejection rejection) {
		if(rejectionDao.removeByEntity(rejection)>0){
			UserRejection userRejection=new UserRejection();
			userRejection.setRejectionId(rejection.getId());
			userRejectionDao.removeByEntity(userRejection);
		}
	}

	@Override
	public List<String> findRejectionClients(Rejection userRejection) {
		return rejectionDao.findRejectionClients(userRejection);
	}

	@Override
	public List<Rejection> findDayNotEnd(Rejection re) {
		return rejectionDao.findDayNotEnd(re);
	}

	@Override
	public List<UserCompanyInfoForm> findFlingEnterprise(Map<String, Object> params) {
		return rejectionDao.findFlingEnterprise(params);
	}

	@Override
	public Page<Rejection> page1(Rejection entity) {
		int limitStart = entity.getLimitStart(),limitEnd = entity.getLimitEnd();
		long count = getEntityDao().countByEntity(entity);
		Page<Rejection> page = new Page<Rejection>((int)(limitEnd/(limitEnd-limitStart)), (limitEnd-limitStart));
		page.setData(rejectionDao.page1(entity));
		page.setTotalCount(count);
		return page;
	}

    
}